<?php
/**
 * Created by PhpStorm.
 * User: Lenovo
 * Date: 2018/11/29
 * Time: 13:40
 */

namespace app\api\controller;

use app\api\model\Submessage;
use think\Controller;
use think\Request;

class Submessages extends Controller
{
    //新增意见
    public function addOpinion(){
        $request=Request::instance();
        $data=$request->post();
        $re=(new \app\api\validate\Evalute())->goCheck();
        if($re===true){
            $re=Submessage::addOpinion($data);
            if(!$re){
                AjaxReturn('0','提交失败');
            }else{
                AjaxReturn('1','提交成功');
            }
        }else{
            AjaxReturn('90001',$re);
        }
    }
    //新增投稿
    public function addContribute(){
        $request=Request::instance();
        $data=$request->post();
        $re=(new \app\api\validate\Evalute())->goCheck();
        if($re===true){
            $re=Submessage::addContribute($data);
            if(!$re){
                AjaxReturn('0','提交失败');
            }else{
                AjaxReturn('1','提交成功');
            }
        }else{
            AjaxReturn('90001',$re);
        }
    }
    //新增订购
    public function addOrder(){
        $request=Request::instance();
        $data=$request->post();
        $re=(new \app\api\validate\Evalute())->goCheck();
        if($re===true){
            $re=Submessage::addOrder($data);
            if(!$re){
                AjaxReturn('0','提交失败');
            }else{
                AjaxReturn('1','提交成功');
            }
        }else{
            AjaxReturn('90001',$re);
        }
    }
    //显示意见箱历史纪录
    public function getOpinion(){
        $userid=$_GET['userid'];
        $re=Submessage::where('userid',$userid)->where('type',0)->order('create_time')->select();
        if($re){
            AjaxReturn('1','请求成功',$re);
        }else{
            AjaxReturn('0','请求内容不存在');
        }
    }
    //显示投稿历史纪录
    public function getContribute(){
        $userid=$_GET['userid'];
        $re=Submessage::where('userid',$userid)->where('type',1)->order('create_time')->select();
        if($re){
            AjaxReturn('1','请求成功',$re);
        }else{
            AjaxReturn('0','请求内容不存在');
        }
    }
    //显示订购信息历史纪录
    public function getOrder(){
        $userid=$_GET['userid'];
        $re=Submessage::where('userid',$userid)->where('type',2)->order('create_time')->select();
        if($re){
            AjaxReturn('1','请求成功',$re);
        }else{
            AjaxReturn('0','请求内容不存在');
        }
    }
}